/**
 * 
 * @author TrinhNX
 * @start_date	: Apr 25, 2015
 * @end_date 	:
 */
public class Euler036 {
	public static void main(String[] args) {
		final int MAX = 1000000;
		final long start = System.currentTimeMillis();
		System.out.println("Start");
		int sum = 0;
		for (int i = 1; i < MAX; i = i + 2) {
			if (checkPalindrom(Integer.toString(i)) && checkPalindrom(Integer.toBinaryString(i))) {
				sum += i;
			}
		}
		System.out.println(sum);
		System.out.println("End: " + (System.currentTimeMillis() - start));
	}

	/**
	 * Check the palindromic of string
	 * @author		: TrinhNX
	 * @param input
	 * @return
	 * @start_date	: Apr 25, 2015
	 * @end_date	:
	 */
	private static boolean checkPalindrom(final String input) {
		final int length = input.length() - 1;
		for (int i = length / 2; i >= 0; i--) {
			if (input.charAt(i) != input.charAt(length - i))
				return false;
		}
		return true;
	}
}
